﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Google.GData;
using Google.GData.Client;
using Google.GData.Calendar;
using Google.GData.Extensions;
using System.Xml.Linq;
using System.Xml;
using System.Xml.Serialization;
using System.IO;

namespace SuperCalendar.Models
{
    public class Event
    {
        private Guid _id;
        private String _title;
        private String _content;
        private String _category;
        private EventPriority _priority;
        private int _completed;
        private String _googleId;
        private EventTime _time;
        private List<String> _locations;
        private DateTime _published;
        private DateTime _updated;

          public Event()
        {
            _id = Guid.NewGuid();
            _published = DateTime.Now;
            _updated = DateTime.Now;
        }

        public Event(String title):this()
        {
            this._title = title;
        }
        public Guid Id
        {
            get { return _id; }
            set { _id = value; }
        }

        public String Title
        {
            get { return _title; }
            set { _title = value; }
        }
        public String Content
        {
            get { return _content; }
            set { _content = value; }
        }

        public String Category
        {
            get { return _category; }
            set { _category = value; }
        }

        public EventPriority Priority
        {
            get { return _priority; }
            set { _priority = value; }
        }


        public EventTime Time
        {
            get { return _time; }
            set { _time = value; }
        }

        public List<String> Locations
        {
            get { return _locations; }
            set { _locations = value; }
        }

        public int Completed
        {
            get { return _completed; }
            set { _completed = value; }
        }


        public String GoogleId
        {
            get { return _googleId; }
            set { _googleId = value; }
        }

        public override int GetHashCode()
        {
            return this.Id.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            if (this == obj)
                return true;
            Event e = obj as Event;
            if (e == null)
                return false;
            return this.Id.Equals(e.Id);
        }

        public DateTime Published
        {
            get { return _published; }
            set { _published = value; }
        }


        public DateTime Updated
        {
            get { return _updated; }
            set { _updated = value; }
        }

        public override string ToString()
        {
           XmlSerializer ser = new XmlSerializer(typeof(Event));
           StringWriter sw = new StringWriter();
           ser.Serialize(sw, this);
           sw.Close();
           return sw.ToString();
        }

        //public String GoogleETags
        //{
        //    get { return _googleETags; }
        //    set { _googleETags = value; }
        //}

        private bool _isNew;
        public bool IsNew
        {
            get { return _isNew; }
            set { _isNew = value; }
        }
        private bool _isDeleted;
        public bool IsDeleted
        {
            get { return _isDeleted; }
            set { _isDeleted = value; }
        }
    }
}
